package com.fwtai.controller.web;

import com.fwtai.bean.PageFormData;
import com.fwtai.service.web.StoreGoodsService;
import com.fwtai.tool.ToolClient;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 门店商品库存控制层|路由层
 * @作者 田应平
 * @版本 v1.0
 * @QQ号码 444141300
 * @Email service@fwtai.com
 * @创建日期 2024-04-15 17:15:24
 * @官网 <url>http://www.fwtai.com</url>
*/
@RestController
@RequestMapping("/storeGoods")
public class StoreGoodsController{

  private final StoreGoodsService storeGoodsService;

  public StoreGoodsController(final StoreGoodsService storeGoodsService){
    this.storeGoodsService = storeGoodsService;
  }

  /**行内编辑*/
  @PreAuthorize("hasAuthority('store_goods_row_edit')")
  @PostMapping("/edit")
  public void edit(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(storeGoodsService.edit(request),response);
  }

  /**根据id查询对应的数据*/
  @PreAuthorize("hasAuthority('store_goods_row_queryById')")
  @GetMapping("/queryById")
  public void queryById(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(storeGoodsService.queryById(id),response);
  }

  /**获取数据*/
  @PreAuthorize("hasAuthority('store_goods_btn_listData')")
  @GetMapping("/listData")
  public void listData(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(storeGoodsService.listData(new PageFormData(request)),response);
  }

  /**新增门店库存*/
  @PreAuthorize("hasAuthority('store_goods_btn_add')")
  @PostMapping("/addStoreGoods")
  public void addStoreGoods(final String userName,final Integer coupon,final HttpServletResponse response){
    ToolClient.responseJson(storeGoodsService.addStoreGoods(userName,coupon),response);
  }
}